package Array;
import java.util.ArrayList;
import java.util.Arrays;
// 15-三数之和-middle
import java.util.List;
import java.util.Scanner;

public class ThreeSum {
    public List<List<Integer>> threeSum(int[] nums){
        quickSort(nums, 0, nums.length - 1);
        List<List<Integer>> list = new ArrayList<>();
        for(int i = 0; i < nums.length; i++){
            if(nums[i] > 0) break;
            if(i > 0 && nums[i] == nums[i - 1]) continue;
            int j = i + 1, k = nums.length - 1;
            while(j < k){
                int sum = nums[i] + nums[j] + nums[k];
                if(sum == 0){
                    list.add(new ArrayList<Integer>(Arrays.asList(nums[i], nums[j], nums[k])));
                    while(j < k && nums[j] == nums[j + 1]) j++;
                    j++;
                    while(j < k && nums[k] == nums[k - 1]) k--;
                    k--;
                } else if(sum > 0){
                    k--;
                } else {
                    j++;
                }
            }
        }
        return list;
    }
    private void quickSort(int[] nums, int left, int right){
        if(left >= right) return;
        int pivot = partition(nums, left, right);
        quickSort(nums, left, pivot - 1);
        quickSort(nums, pivot + 1, right);
    }
    private int partition(int[] nums, int left, int right){
        int val = nums[left];
        while(left < right){
            while(left < right && nums[right] >= val) right--;
            nums[left] = nums[right];
            while(left < right && nums[left] <= val) left++;
            nums[right] = nums[left];
        }
        nums[left] = val;
        return left;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split(",");
        int[] nums = new int[s.length];
        for(int i = 0; i < s.length; i++){
            nums[i] = Integer.parseInt(s[i]);
        }
        ThreeSum ts = new ThreeSum();
        System.out.println(ts.threeSum(nums));
        sc.close();
    }
}
